/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.app.dao.impl;

import javax.persistence.NoResultException;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.app.dao.AbstractBaseDAO;
import org.app.dao.M_KeywordDAO;
import org.app.model.M_Keyword;
import org.app.model.M_Keyword_;

/**
 *
 * @author mrapple
 */
public class M_KeywordDAOImpl extends AbstractBaseDAO<M_Keyword> implements M_KeywordDAO {

    @Override
    public M_Keyword searchKeyword(String movieName) throws Exception {
        M_Keyword keyword = new M_Keyword();
        try {
            CriteriaQuery<M_Keyword> criteria = builder.createQuery(M_Keyword.class);
            Root<M_Keyword> m_KeywordRoot = criteria.from(M_Keyword.class);
            criteria.select(m_KeywordRoot);
            criteria.where(builder.equal(m_KeywordRoot.get(M_Keyword_.keyword), movieName));
            keyword = em.createQuery(criteria).getSingleResult();
        } catch (NoResultException noResult) {
            keyword = null;
        } catch (Exception e) {
            throw e;
        }
        return keyword;
    }
}
